//
//  ADWindow.swift
//  onemeetingmac
//
//  Created by 张衡 on 2020/7/3.
//  Copyright © 2020 onemeeting. All rights reserved.
//

import Foundation

class ADWindow: TCWindow {
    
}

extension NSWindow {
    func centerIn(window:NSWindow?) {
        if let inWindow = window {
            let x = (inWindow.frame.size.width-self.frame.size.width)/2+inWindow.frame.origin.x
            let y = (inWindow.frame.size.height-self.frame.size.height)/2+inWindow.frame.origin.y+20
            self.setFrame(NSRect.init(origin: CGPoint.init(x: x, y: y), size: self.frame.size), display: true)
        }
    }
    
    func orderInFont(onWindow:NSWindow?,isCenter:Bool=true,sender:Any?)  {
        if let win = onWindow {
            self.level = NSWindow.Level.init(win.level.rawValue)
            if isCenter {
                self.centerIn(window: win)
            }
        }
        self.lorderFront(sender)
    }
    
    func screenSafe() {
        var frame = self.frame
        frame.origin.x = frame.origin.x < 0 ? 0:frame.origin.x
        let maxX = KSCREENWIDTH-frame.size.width
        frame.origin.x = frame.origin.x > maxX ? maxX:frame.origin.x
        
        frame.origin.y = frame.origin.y < 60 ? 60:frame.origin.y
        let maxY = KSCREENHEIGHT-frame.size.height
        frame.origin.y = frame.origin.y > maxY ? maxY:frame.origin.y
        
        self.setFrame(frame, display: true)
    }
}
